home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Source Code
/
PowerPlant
/
AGA Classes 1.2
/
Progress Indicators
/
LAGAProgressIndicator.cp
< prev
next >
Wrap
Text File
|
1996-06-30
|
8KB
|
271 lines
// ===========================================================================
// LAGAProgressIndicator.cp
// ===========================================================================
// “Apple Grayscale Appearance” compliant Determinate progress indicator control
// Copyright © 1996 Chrisoft (Christophe ANDRES) All rights reserved.
//
// You may use this source code in any application (commercial, shareware, freeware,
// postcardware, etc), but not remove this notice (no need to acknowledge the use of
// this class in the about box)
// You may not sell this source code in any form. This source code may be placed on
// publicly accessable archive sites and source code disks. It may not be placed on
// profit archive sites and source code disks without the permission of the author,
// Christophe ANDRES.
//
// This source code is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// If you make any change or improvement on this class, please send the improved/changed
// version to : chrisoft@calva.net or Christophe ANDRES
// 20, rue Prosper Mérimée
// 67100 STRASBOURG
// FRANCE
//
// ===========================================================================
// LAGAProgressIndicator.h <- double-click + Command-D to see class declaration
//
// LAGAProgressIndicator is my implementation of the “Apple Grayscale Appearance for System 7.5”
// determinate progress indicator.
// Use the IncrementValue or SetValue methods to update the progress indicator
//
// This class requires AGAColors.cp to be present in your project
//
// Version : 1.2
//
// Change History (most recent first, date in US form : mm/dd/yy):
//
// 06/30/96 ca Public release of version 1.2
// 06/28/96 ca Bug in SetMaxValue : wrongly affected inMaxValue to mMinValue
// 06/04/96 ca added RegisterClass method for easy registry
// Increased version to 1.2
// 05/21/96 ca class made available by Christophe ANDRES <chrisoft@calva.net>
// (version 1.1)
//
// To Do:
//
#include "LAGAProgressIndicator.h"
#include <UEnvironment.h>
#include "AGAColors.h"
const short kIndicatorHeight = 14;
const short kMinimumWidth = 8;
// begin <06/04/96 ca>
void LAGAProgressIndicator::RegisterClass ()
{
URegistrar::RegisterClass(LAGAProgressIndicator::class_ID, (ClassCreatorFunc)LAGAProgressIndicator::CreateAGAProgressIndicatorStream);
}
// end <06/04/96 ca>
LAGAProgressIndicator* LAGAProgressIndicator::CreateAGAProgressIndicatorStream (LStream* inStream)
{
return (new LAGAProgressIndicator(inStream));
}
//-------Constructors-------------------------------------------------------------------------------------------------
LAGAProgressIndicator::LAGAProgressIndicator (LStream *inStream) : LPane(inStream)
{
inStream->ReadData(&mValue, sizeof(Int32));
inStream->ReadData(&mMinValue, sizeof(Int32));
inStream->ReadData(&mMaxValue, sizeof(Int32));
// Boundary checks
if (mMinValue >= mMaxValue)
mMaxValue = mMinValue + 10;
if ((mValue < mMinValue) || (mValue > mMaxValue))
mValue = mMinValue;
if (mFrameSize.height < kIndicatorHeight)
mFrameSize.height = kIndicatorHeight;
if (mFrameSize.width < kMinimumWidth)
mFrameSize.width = kMinimumWidth;
}
LAGAProgressIndicator::LAGAProgressIndicator (const LAGAProgressIndicator &inOriginal) : LPane(inOriginal)
{
mMinValue = inOriginal.mMinValue;
mMaxValue = inOriginal.mMaxValue;
mValue = inOriginal.mValue;
// Boundary checks
if (mMinValue >= mMaxValue)
mMaxValue = mMinValue + 10;
if ((mValue < mMinValue) || (mValue > mMaxValue))
mValue = mMinValue;
if (mFrameSize.height < kIndicatorHeight)
mFrameSize.height = kIndicatorHeight;
if (mFrameSize.width < kMinimumWidth)
mFrameSize.width = kMinimumWidth;
}
LAGAProgressIndicator::LAGAProgressIndicator (const SPaneInfo &inPaneInfo, Int32 inInitialValue, Int32 inMinValue, Int32 inMaxValue)
: LPane(inPaneInfo)
{
mMinValue = inMinValue;
mMaxValue = inMaxValue;
mValue = inInitialValue;
// Boundary checks
if (mMinValue >= mMaxValue)
mMaxValue = mMinValue + 10;
if ((mValue < mMinValue) || (mValue > mMaxValue))
mValue = mMinValue;
if (mFrameSize.height < kIndicatorHeight)
mFrameSize.height = kIndicatorHeight;
if (mFrameSize.width < kMinimumWidth)
mFrameSize.width = kMinimumWidth;
}
//-------Drawers----------------------------------------------------------------------------------------------------
void LAGAProgressIndicator::DrawSelf ()
{
StColorPenState theState;
Boolean hasColor = ::PaneInColor(this);
Rect frame;
theState.Normalize();
CalcLocalFrameRect(frame);
frame.bottom = frame.top + kIndicatorHeight;
if (hasColor)
{
::RGBForeColor(&gAGAColorArray[5]);
::MoveTo(frame.left, frame.top + 12);
::Line(0, -12);
::LineTo(frame.right - 2, frame.top);
::ForeColor(whiteColor);
::Move(1, 1); ::Line(0, 12);
::LineTo(frame.left + 1, frame.bottom - 1);
}
::ForeColor(blackColor);
::InsetRect(&frame, 1, 1);
::FrameRect(&frame);
::InsetRect(&frame, 1, 1);
if (hasColor)
{
StClipRgnState theClip;
theClip.ClipToIntersection(frame);
double size = (frame.right - frame.left) - 4;
double division = size / (double)((mMaxValue - 1) - mMinValue);
short indicLength = division * ((mValue - 1) - mMinValue);
if (mValue > mMinValue)
{
::RGBForeColor(&gAGAColorArray[8]);
::MoveTo(frame.left + 1, frame.top);
::Line(-1, 0);
::Line(0, 9);
::Move(1, -1); ::Line(0, 0);
::Move(1, -1); ::Line(indicLength, 0);
::Move(1, -6); ::Line(-(indicLength + 1), 0);
::RGBForeColor(&gAGAColorArray[10]);
::Move(0, -1); ::Line(indicLength + 2, 0);
::Move(2, 0); ::Line(0, 9);
::Move(-3, -7); ::Line(0, 6);
::Line(-(indicLength + 1), 0);
::Move(-1, 1); ::Line(0, 0);
::RGBForeColor(&gAGAColorArray[5]);
::Move(0, -2); ::Line(0, 0);
::Move(1, -1); ::Line(indicLength, 0);
::Move(0, -4); ::Line(-indicLength, 0);
::Move(-1, -1); ::Line(0, 0);
::RGBForeColor(&gAGAColorArray[3]);
::Move(0, 1); ::Line(0, 0);
::Move(1, 1); ::Line(indicLength, 0);
::Line(0, 2); ::Line(-indicLength, 0);
::Move(-1, 1); ::Line(0, 0);
::RGBForeColor(&gAGAColorArray[1]);
::Move(0, -1); ::Line(0, -2);
::Move(1, 1); ::Line(indicLength - 1, 0);
::RGBForeColor(&gAGAColorArray[12]);
::Move(3, -3); ::Line(0, 8);
::Line(-(indicLength + 2), 0);
::ForeColor(blackColor);
::Move(indicLength + 3, 0);
::Line(0, -9);
}
if (mValue < mMaxValue)
{
::RGBBackColor(&gAGAColorArray[4]);
if (mValue > mMinValue)
frame.left = frame.left + indicLength + 7;
EraseRect(&frame);
::RGBForeColor(&gAGAColorArray[7]);
::MoveTo(frame.left, frame.bottom - 1);
::Line(0, -9); ::LineTo(frame.right - 2, frame.top);
::RGBForeColor(&gAGAColorArray[2]);
::Move(1, 1); ::Line(0, 8);
::LineTo(frame.left + 1, frame.bottom - 1);
}
}
else
{
double size = frame.right - frame.left;
double division = size / (double)(mMaxValue - mMinValue);
Rect r = frame;
r.right = r.left + (division * (mValue - mMinValue));
::FillRect(&frame, &qd.black);
frame.left = r.right;
if (!::EmptyRect(&frame))
EraseRect(&frame);
}
}
void LAGAProgressIndicator::IncrementValue (Int32 inIncrement)
{
SetValue(mValue + inIncrement);
}
void LAGAProgressIndicator::SetValue (Int32 inValue)
{
if ((inValue != mValue) && (inValue >= mMinValue) && (inValue <= mMaxValue))
{
mValue = inValue;
if (FocusDraw())
DrawSelf();
}
}
void LAGAProgressIndicator::SetMinValue (Int32 inMinValue)
{
if ((inMinValue != mMinValue) && (inMinValue <= mMaxValue))
{
if (mValue < inMinValue)
mValue = inMinValue;
mMinValue = inMinValue;
if (FocusDraw())
DrawSelf();
}
}
void LAGAProgressIndicator::SetMaxValue (Int32 inMaxValue)
{
if ((inMaxValue != mMaxValue) && (inMaxValue >= mMinValue))
{
if (mValue > inMaxValue)
mValue = inMaxValue;
mMaxValue = inMaxValue; // <06/28/96 ca>
if (FocusDraw())
DrawSelf();
}
}